package com.app.biz.controller;

import com.app.biz.domain.BizAnnualShandongTopTenIndustrialCounty;
import com.app.biz.domain.BizGycpcxl;
import com.app.biz.service.IBizAnnualShandongTopTenIndustrialCountyService;
import com.app.common.annotation.Log;
import com.app.common.config.AppConfig;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.AjaxResult;
import com.app.common.core.page.TableDataInfo;
import com.app.common.enums.BusinessType;
import com.app.common.utils.file.FileUploadUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/biz/annual/top/industry/county")
public class BizAnnualShandongTopTenIndustrialCountyController extends BaseController
{
    @Autowired
    private IBizAnnualShandongTopTenIndustrialCountyService service;




    @GetMapping("/list")
    public TableDataInfo list(BizAnnualShandongTopTenIndustrialCounty bizAnnualShandongTopTenIndustrialCounty)
    {
        startPage();
        List<BizAnnualShandongTopTenIndustrialCounty> list = service.selectBizAnnualShandongTopTenIndustrialCountyList(bizAnnualShandongTopTenIndustrialCounty);
        return getDataTable(list);
    }





    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(service.selectBizAnnualShandongTopTenIndustrialCountyByBaseId(baseId));
    }



    @Log(title = "年度山东省工业十强县名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizAnnualShandongTopTenIndustrialCounty bizAnnualShandongTopTenIndustrialCounty)
    {
        return toAjax(service.insertBizAnnualShandongTopTenIndustrialCounty(bizAnnualShandongTopTenIndustrialCounty));
    }


    @Log(title = "年度山东省工业十强县名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizAnnualShandongTopTenIndustrialCounty bizAnnualShandongTopTenIndustrialCounty)
    {
        return toAjax(service.updateBizAnnualShandongTopTenIndustrialCounty(bizAnnualShandongTopTenIndustrialCounty));
    }


    @Log(title = "年度山东省工业十强县名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(service.deleteBizAnnualShandongTopTenIndustrialCountyByBaseIds(baseIds));
    }

    @PostMapping("/importExcel")
    public AjaxResult importExcel(@RequestParam Map<String,String> params, @RequestPart("file") MultipartFile multipartFile){
        try{
            String year = params.get("year");
            if(StringUtils.isBlank(year)){
                return AjaxResult.warn("请选择导入的年份");
            }

            /* 上传文件的路径 */
            String uploadPath = FileUploadUtils.upload(AppConfig.getProfile(),multipartFile);
            String absoluteExcelPath = FileUploadUtils.replaceAbsolutePath(uploadPath);
            AjaxResult ajaxResult = service.importExcel(absoluteExcelPath, year);
            return ajaxResult;
        }catch (IOException e){
            return AjaxResult.error("导入失败");
        }
    }


}
